<!--
 * @Author: zhangjingyu
 * @Date: 2021-04-06 11:30:24
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-05-18 17:07:26
 * @FilePath: \vprisk10.14\src\views\ftpManage\pricingManage\sceneTask\sceneTask_viewFilterData.vue
 * @Description:情景定价查看筛选数据页面
-->
<template>
  <div>
        <span class="formTitle"><i class="vertical-bar"></i>情景定价查看筛选数据</span>
    <!-- 操作区域 -->
    <upper-template
      @search="(searchForm.page = 1), searchFunc()"
      @clear="clearSearch"
      :configIcon="false"
    >
      <!-- 操作按钮区 -->
      <template slot="buttonArea">
        <el-button @click="delFunc()">删除</el-button>
        <el-button @click="delAllFunc()">全部删除</el-button>
        <el-button @click="filterData()">筛选数据</el-button>
        <el-button @click="trial()">执行定价</el-button>
        <el-button @click="backIndex()">返回</el-button>
      </template>
      <!-- 搜索区 -->
      <template slot="searchArea">
        <el-form
          :model="searchForm"
          ref="searchForm"
          label-width="140px"
          label-position="left"
          size="mini"
        >
        <el-form-item label="情景分析定价编号：">
            <el-input
              v-model="searchForm.taskCode"
              disabled
              style="width:150px"
            ></el-input>
          </el-form-item>
           <el-form-item label="情景：">
            <el-input
              v-model="sceneName"
              style="width:150px"
              disabled
            ></el-input>
          </el-form-item>
           <el-form-item label="头寸数据表：">
            <el-select v-model="searchForm.position" 
              style="width:150px"
           >
              <el-option v-for="item in positionList" 
              :key="item.pdPostFix"
              :value="item.pdPostFix"
              :label="item.pdName"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="账号：">
            <el-input
              v-model="searchForm.acctNo"
              style="width:150px"
            ></el-input>
          </el-form-item>
          <el-form-item label="机构：" prop="orgCd">
            <auto-form
              v-model="searchForm.orgCd"
              elementType="6"
              dimCode="cpm_dim_organ"
              style="width:150px"
            ></auto-form>
          </el-form-item>
          <el-form-item label="科目：" prop="sbjtCd">
            <auto-form
              v-model="searchForm.sbjtCd"
              elementType="6"
              dimCode="cpm_dim_subject"
              style="width:150px"
            ></auto-form>
          </el-form-item>
          <el-form-item label="币种：" prop="ccyCd">
            <el-select v-model="searchForm.ccyCd" style="width:150px">
              <el-option
                v-for="item in currencyList"
                :key="item.ccyCd"
                :value="item.currencyCode"
                :label="item.currencyName"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </template>
    </upper-template>
    <el-table ref="multipleTable" :data="tableData" @row-click="rowChecked">
      <el-table-column
        width="55"
        type="selection"
        
      ></el-table-column>
      <el-table-column prop="acct_no" label="账号" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="org_cd" label="机构" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="sbjt_cd" label="科目" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="prd_cd" label="产品" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="industry_cd" label="行业" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="ccy_cd" label="币种" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="cust_no" label="客户编号" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="cur_bal" label="当前余额" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="orig_amt" label="原始余额" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="pmt_bal" label="支付余额" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="start_dt" label="起息日" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="matu_dt" label="到期日" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="exec_rate" label="执行利率" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="flt_tp_cd" label="浮动类型代码" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="flt_ratio" label="浮动比例" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="flt_margin" label="浮动利差" show-overflow-tooltip>
      </el-table-column>
    </el-table>
     <pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="searchForm.page"
        :page-size="searchForm.size"
        @refresh="searchFunc"
        :total="total"
      ></pagination>
  </div>
</template>

<script>
import autoForm from "@/components/ftp/autoForm.vue";
import { publicManage_pub, pricingTask } from "@/api/index";
export default {
  components: { autoForm },
  props: {
    baseData: Object
  },
  data() {
    return {
      sceneName: this.baseData.sceneName,
      searchForm: {
        taskCode: this.baseData.taskCode,
        sceneCode: this.baseData.sceneCode,
        position:this.baseData.positionList[0].pdPostFix,
        pdPostFix: "",
        acctNo: "",
        orgCd: "",
        sbjtCd: "",
        ccyCd: "",
        page: 1,
        size: 15
      },
      positionList:[],
      tableData: [],
      total:0,
      currencyList: []
    };
  },
  created() {
    this.getCcyList();
    this.searchFunc();
    this.getPositionList();
  },
  watch: {
    baseData: {
      handler(newV, oldV) {
        this.searchForm.taskCode = this.baseData.taskCode;
        this.searchForm.sceneCode = this.baseData.sceneCode;
        this.sceneName = this.baseData.sceneName;
        this.searchFunc();
      },
      deep: true,
      immediate: true
    }
  },
  methods: {
    // 获取可用币种
    getCcyList() {
      publicManage_pub
        .currencyManageQueryAvailable({ page: 1, size: 999 })
        .then(res => {
          this.currencyList = res.data;
        });
    },
    clearSearch() {
      (this.searchForm.acctNo = ""),
        (this.searchForm.orgCd = ""),
        (this.searchForm.sbjtCd = ""),
        (this.searchForm.ccyCd = ""),
        (this.searchForm.page = 1);
    },
    searchFunc() {
      let data = this.searchForm;
      data.pdPostFix=data.position;
      pricingTask.sceneTaskViewDataQuery(data).then(res => {
         if(res.code==200){
          this.tableData = res.rows
          this.total = res.total
        }
      });
    },
    // 全部删除
    delAllFunc() {
      if(this.total==0){
        this.$message.warning("没有可删除的数据");
        return;
      }
      let data = { taskCode: this.searchForm.taskCode };
      pricingTask.sceneTaskRemoveDataByTaskCode(data).then(res => {
        if (res.code == 200) {
          this.$message.success("删除成功");
          this.searchFunc();
        } else {
          this.$message.error(res.message || "删除失败");
        }
      });
    },
    // 单个删除
    delFunc() {
      let selection = this.$refs.multipleTable.selection;
      if (selection.length < 1) {
        return this.$message.warning("请选择要删除的数据");
      }
      this.$confirm("您确定要删除选中数据吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let data = { accountNums: selection.map(v => v.acctNo) ,taskCode:this.searchForm.taskCode };
          pricingTrial.sceneTaskRemove(data).then(res => {
            if (res.code == 200) {
              this.$message.success("删除成功");
              this.searchFunc();
            } else {
              this.$message.error(res.message || "删除失败");
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    // 执行定价
    trial() {
      let data = { taskCode: this.searchForm.taskCode };
       pricingTask.sceneTaskExcute(data).then(res=>{
        if(res.code==200){
          this.$message.success('情景定价任务执行成功！')
        }else{
          this.$message.error(res.message)
        }
      })
    },
    // 筛选数据
    filterData() {
        this.$emit('toDataFilter',true)
    },
    // 返回
    backIndex() {
      this.$emit("backIndex", false);
    },
    rowChecked(row) {
      if (this.$refs.multipleTable) {
        this.$refs.multipleTable.clearSelection();
        this.$refs.multipleTable.toggleRowSelection(row, true);
      }
    },
    getPositionList(){
      console.log(this.baseData,'baseData')
          this.positionList = this.baseData.positionList||[];
    },
    handleSizeChange(val) {
      this.searchForm.size = val;
      this.searchFunc();
    },
    handleCurrentChange(val) {
      this.searchForm.page = val;
      this.searchFunc();
    }
  }
};
</script>

<style lang="scss" scoped>
.formTitle {
  font-size: 14px;
  font-weight: 700;
  display: block;
  margin-bottom: 10px;
}
</style>